package com.sugar.subscribe.course.module.business.controller.app.withdrawrecord;

import com.sugar.subscribe.course.framework.common.pojo.CommonResult;
import com.sugar.subscribe.course.framework.common.pojo.PageParam;
import com.sugar.subscribe.course.framework.common.pojo.PageResult;
import com.sugar.subscribe.course.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.subscribe.course.module.business.controller.app.withdrawrecord.vo.AppWithdrawRecordRespVO;
import com.sugar.subscribe.course.module.business.controller.app.withdrawrecord.vo.AppWithdrawRecordSaveReqVO;
import com.sugar.subscribe.course.module.business.service.withdrawrecord.WithdrawRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import static com.sugar.subscribe.course.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 提现记录")
@RestController
@RequestMapping("/biz/withdraw-record")
@Validated
public class AppWithdrawRecordController {

    @Resource
    private WithdrawRecordService withdrawRecordService;

    @PostMapping("/create")
    @Operation(summary = "余额提现")
    public CommonResult<Boolean> userWithdraw(@Valid @RequestBody AppWithdrawRecordSaveReqVO createReqVO) {
        withdrawRecordService.appUserWithdraw(createReqVO.getAmount(), SecurityFrameworkUtils.getLoginUserId(true));
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "获得提现记录分页")
    public CommonResult<PageResult<AppWithdrawRecordRespVO>> getWithdrawRecordPage(@Valid PageParam pageParam) {
        return success(withdrawRecordService.appGetWithdrawRecordPage(pageParam, SecurityFrameworkUtils.getLoginUserId(true)));
    }
}